#include "stdafx.h"



 //#include "..\public\BiocareDB\BiocareDB.h"

#include "globals.h"

 

 CString GetECGStudyResult(int nType, CString strLoadLanguage, ECGMachineType ecgMacType, int nContent)
{
	CString strRet = "";

	STUDY_RESULT studyResult;
	if(ecgMacType == ECG_MACHINE_TYPE_9801_SERIES)
	{
		if (strLoadLanguage.GetLength() == NULL || !strLoadLanguage.CompareNoCase("CHN")) {
			strRet.Format("%s", ECG_STUDY_RESULT[nType].szResultChn);
		}else if (!strLoadLanguage.CompareNoCase("ENG")) {
			strRet.Format("%s", ECG_STUDY_RESULT[nType].szResultEng);
		}else if (!strLoadLanguage.CompareNoCase("RUS")) 
		{
			
			char szTemp[512];
			memset(szTemp,0, sizeof(szTemp));
 			strRet.Format("%s", GBK_to_1251(ECG_STUDY_RESULT[nType].szResultRus,szTemp));
		}


		CString strContent = "";
		int nTemp = nContent;
		if((nTemp & 0xF000) == 0xF000){
			if((nTemp & 0x0001) == 0x0001){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "I";
			}
			if((nTemp & 0x0002) == 0x0002){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "II";
			}
			if((nTemp & 0x0004) == 0x0004){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "III";
			}
			if((nTemp & 0x0008) == 0x0008){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "aVR";
			}
			if((nTemp & 0x0010) == 0x0010){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "aVL";
			}
			if((nTemp & 0x0020) == 0x0020){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "aVF";
			}
			if((nTemp & 0x0040) == 0x0040){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "V1";
			}
			if((nTemp & 0x0080) == 0x0080){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "V2";
			}
			if((nTemp & 0x0100) == 0x0100){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "V3";
			}
			if((nTemp & 0x0200) == 0x0200){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "V4";
			}
			if((nTemp & 0x0400) == 0x0400){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "V5";
			}
			if((nTemp & 0x0800) == 0x0800){
				if(strContent.GetLength() > 0){
					strContent += ",";
				}
				strContent += "V6";
			}
			if(strContent.GetLength() > 0){
				strRet += "(";
				strRet += strContent;
				strRet += ")";
			}
		}
	}else if(ecgMacType == ECG_MACHINE_TYPE_6010_SERIES){
		for (int nLoop = 0; nLoop < ANALYSE_ENCODE_SIZE; ++nLoop)
		{
			if (ECG_STUDY_RESULT[nLoop].nCode == nType) {
				if (strLoadLanguage.GetLength() == NULL || !strLoadLanguage.CompareNoCase("CHN")) {
					strRet.Format("%s", ECG_STUDY_RESULT[nLoop].szResultChn);
				}else if (!strLoadLanguage.CompareNoCase("ENG")) {
					strRet.Format("%s", ECG_STUDY_RESULT[nLoop].szResultEng);
				}else if (!strLoadLanguage.CompareNoCase("RUS"))
				{
					//strRet.Format("%s", ECG_STUDY_RESULT[nLoop].szResultRus);
					char szTemp[512];
					memset(szTemp,0, sizeof(szTemp));
 					strRet.Format("%s", GBK_to_1251(ECG_STUDY_RESULT[nLoop].szResultRus,szTemp));

				}
				
				if (ECGStudyResultTypeInContent(nType))
				{
					CString strContent = "";
					int nTemp = nContent;
					if((nTemp & 0x01 )== 0x01){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "I";
					}

					if((nTemp & 0x02) == 0x02){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "II";
					}
					if((nTemp & 0x04) == 0x04){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "III";
					}
					if((nTemp & 0x08) == 0x08){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "aVR";
					}
					if((nTemp & 0x10) == 0x10){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "aVL";
					}
					if((nTemp & 0x20) == 0x20){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "aVF";
					}
					if((nTemp & 0x40) == 0x40){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "V1";
					}
					if((nTemp & 0x80) == 0x80){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "V2";
					}
					if((nTemp & 0x0100) == 0x0100){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "V3";
					}
					if((nTemp & 0x0200) == 0x0200){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "V4";
					}
					if((nTemp & 0x0400) == 0x0400){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "V5";
					}
					if((nTemp & 0x0800) == 0x0800){
						if(strContent.GetLength() > 0){
							strContent += ",";
						}
						strContent += "V6";
					}

					if(strContent.GetLength() > 0){
						strRet += "(";
						strRet += strContent;
						strRet += ")";
					}
				}
			}
		}
	}

	return strRet;
}



/*
 
 CString GetECGStudyResultFromDatabase(int nCode , CString strLoadLanguage )
{
	CString strRet = "";

	return strRet;

 
	
	char szErrorMsg[1024];
	memset(szErrorMsg, 0, 1024);
	BCDBConnection DBConn;

//	CECGWorkStationApp* theApp = (CECGWorkStationApp*)AfxGetApp();

	CString m_strConnection="";

	if(!BCDBConnectDB(&DBConn, (LPCTSTR)m_strConnection,m_strConnection, m_strConnection, szErrorMsg)){
//	if(!BCDBConnectDB(&DBConn, (LPCTSTR)theApp->m_strConnection, (LPCTSTR)theApp->m_strConnUserName, (LPCTSTR)theApp->m_strConnPassWord, szErrorMsg)){
		return strRet;
	}
	
	try
	{
		_ConnectionPtr pConnection = DBConn.pConnection;
		_RecordsetPtr pRecordset;
		HRESULT hr = pRecordset.CreateInstance("ADODB.Recordset");
		if(!SUCCEEDED(hr))
		{
			AfxMessageBox("ADO Recordset - CreateInstance failed.");
			pConnection->Close();
			pConnection.Release();
			return  strRet   ;
		}
		
		_variant_t RecordsAffected ;
		CString strSQL = "" ; 
		
		strSQL.Format("SELECT MODEL_CONTENT_CHINESE ,MODEL_CONTENT_ENGLISH,MODEL_CONTENT_RUSS from  t_model  WHERE MODEL_RECORD_CODE= '%d'"
			,nCode );
		
		
		
		hr = pRecordset->Open((_bstr_t)strSQL,
			_variant_t((IDispatch*)pConnection,true),
			adOpenStatic,adLockOptimistic,adCmdText);
		if(!SUCCEEDED(hr))
		{
			AfxMessageBox("ADO Recordset open - Open recordset failed.");
			pRecordset->Release();
			pConnection->Close();
			pConnection->Release();
			
			return  strRet ;
		}
		
		
		
		if (pRecordset->adoEOF) 
		{
			return strRet;
		}
		else
		{
			if(!strLoadLanguage.CompareNoCase("CHN"))
				strRet = (LPCTSTR) (_bstr_t) (pRecordset->GetCollect(_variant_t((long)0)));	
			else if(!strLoadLanguage.CompareNoCase("ENG"))
				strRet = (LPCTSTR) (_bstr_t) (pRecordset->GetCollect(_variant_t((long)1)));	
			else if(!strLoadLanguage.CompareNoCase("RUS"))
				strRet = (LPCTSTR) (_bstr_t) (pRecordset->GetCollect(_variant_t((long)2)));	
			
		}
		
		pRecordset->Close();
		pRecordset->Release();
		
		BCDBDisconnectionDB(&DBConn, szErrorMsg);
		
	} //try 
	catch(_com_error e)
	{
		CString strErrorMsg = "";
		strErrorMsg.Format("Database operator error!\rSource:%s\nDescription:%s",e.Source(),e.Description());
		AfxMessageBox(strErrorMsg);
	}



	return strRet;

 
}

 
  */


 

  CString GetECGStudyResult(ECG_DATA_DEF* pECGData, CString strLoadLanguage)
{
	CString strText, strTemp, strResult;
	int nPos = 0;
	if (pECGData->ecgMacType == ECG_MACHINE_TYPE_9801_SERIES) {
		strTemp = "";
		int nResultCount = 0;
		for (int nLoop = 0; nLoop < ANALYSE_ENCODE_SIZE; ++nLoop)
		{
			if (pECGData->ecgData9801Series.AnalyseEncode[nLoop] > 0) {
				nResultCount++;
				if (strTemp.GetLength() > 0) {
					strTemp += "\r\n";
					strResult = GetECGStudyResult(nLoop, strLoadLanguage, ECG_MACHINE_TYPE_9801_SERIES,pECGData->ecgData9801Series.AnalyseEncode[nLoop]);
					if (pECGData->ecgPatData.strStudyResultManu.Find(strResult) >= 0) {
					}else strTemp += strResult;
				}else{
					strResult = GetECGStudyResult(nLoop, strLoadLanguage, ECG_MACHINE_TYPE_9801_SERIES,pECGData->ecgData9801Series.AnalyseEncode[nLoop]);
					if (pECGData->ecgPatData.strStudyResultManu.Find(strResult) >= 0) {
						strTemp = "";
					}else strTemp = strResult;
				}
			}
		}
		if (pECGData->ecgPatData.strStudyResultManu.GetLength() > 0) {
			if (strTemp.GetLength() > 0) {
				strTemp += "\r\n";
				strTemp += pECGData->ecgPatData.strStudyResultManu;
			}else{
				strTemp = pECGData->ecgPatData.strStudyResultManu;
			}
		}
		strText += strTemp;
	}else if (pECGData->ecgMacType == ECG_MACHINE_TYPE_6010_SERIES){
		strTemp = "";
		int nResultCount = 0;
		for(int nLoop = 0; nLoop < 8; ++nLoop)
		{
			if(pECGData->ecgData6010Series.AnalyseResult.CodeNum[nLoop] > 0){
				nResultCount++;
				if (strTemp.GetLength() > 0) {
					strTemp += "\r\n";
					strResult = GetECGStudyResult(pECGData->ecgData6010Series.AnalyseResult.CodeNum[nLoop], strLoadLanguage, ECG_MACHINE_TYPE_6010_SERIES,pECGData->ecgData6010Series.AnalyseResult.Content[nLoop]);
					if (pECGData->ecgPatData.strStudyResultManu.Find(strResult) >= 0) {
					}else strTemp += strResult;
				}else{
					strResult = GetECGStudyResult(pECGData->ecgData6010Series.AnalyseResult.CodeNum[nLoop], strLoadLanguage, ECG_MACHINE_TYPE_6010_SERIES,pECGData->ecgData6010Series.AnalyseResult.Content[nLoop]);
					if (pECGData->ecgPatData.strStudyResultManu.Find(strResult) >= 0) {
						strTemp = "";
					}else strTemp = strResult;
				}
			}
		}
		if (pECGData->ecgPatData.strStudyResultManu.GetLength() > 0) {
			if (strTemp.GetLength() > 0) {
				strTemp += "\r\n";
				strTemp += pECGData->ecgPatData.strStudyResultManu;
			}else{
				strTemp = pECGData->ecgPatData.strStudyResultManu;
			}
		}
		strText += strTemp;
	}

	return strText;
}





  